package com.dhl.shipment;

import com.dhl.dao.DHLDao;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.jws.WebService;
import javax.ejb.Stateless;
import javax.sql.DataSource;

@WebService(name = "DHLService", serviceName = "DHLService")
@Stateless()
public class DHLShipmentTestSoapImpl
{
    
    private DHLDao dao;
    @Resource(mappedName = "jdbc/Servientrega", type = DataSource.class)
    DataSource dsOMS;

    @PostConstruct
    void postConstruct() {
        dao = new DHLDao(dsOMS);
    }
    
    
    public boolean fullfillShipment(Shipment shipment) throws Exception {
        
        boolean item = false;
        try {

            item = dao.CreateShipment(shipment);
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }
        return item;
        
        /*
        
        Calendar calendar = Calendar.getInstance();
        int minutes = calendar.get(Calendar.MINUTE);
        minutes = minutes- ((minutes/10)*10);
        return minutes%2==0; */
    }


    /**
     * @param orderId
     * @return 
     *    Provider
     *    Transit
     *    Delivered
     */
    public String checkShipmentStatus(String orderId) throws Exception {
        String item = "-1";
        try {

            item = dao.getShipmenStatus(Long.valueOf(orderId));
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }
        return item;
        
        /* Calendar calendar = Calendar.getInstance();
        int minutes = calendar.get(Calendar.MINUTE);
        minutes = minutes- ((minutes/10)*10);        
        if (minutes == 2 || minutes == 5 || minutes == 8)
            return "Provider";
        else if (minutes == 0 || minutes == 3 || minutes == 6)
            return "Transit";
        else
            return "Delivered";*/
    }
}
